# 调用OS库
import os
def getFileSize(path):
    # 获取目录生成列表
    dirs = os.listdir(path)
    sum_size = 0
    # 遍历列表
    for file in dirs:
        path_abs = os.path.join(path, file)
        # 判断路径是否为文件或者目录
        if os.path.isfile(path_abs):
            size = os.path.getsize(path_abs)
            sum_size += size
        if os.path.isdir(path_abs):
            sum_size += getFileSize(path_abs)
    return sum_size
path = input('请输入文件的绝对路径：')
print('文件大小为{}字节'.format(getFileSize(path)))

